

gen year = taxyr_out

capture rename have_1040 i_1040

***Adjust for outcomes for inflation and create alternate wage measures with zeroes for missing 1040s***
merge m:1 year using ${supp_data}/eitc_params_yr, keep(match master) gen(_m_cpi) keepusing(cpi_jan cpi_2015)
global ys = "wage"
foreach y of global ys {
	rename `y' `y'_unadj
	gen `y' = `y'_unadj*(cpi_2015/cpi_jan)

	*Cap at 99 percentile (adjusted for inflation)
	summ `y', detail
	replace `y' =r(p99) if `y'>r(p99) & `y'!=.
	replace `y'_unadj =r(p99)*(cpi_jan/cpi_2015) if `y'>r(p99) & `y'!=.

	gen `y'z = `y'
	replace `y'z = 0 if `y'==. & i_1040==0
}

***Create 3 year average (exclude missing years)***
xtset pik taxyr_out

replace wagez = . if inrange(taxyr_out,2019,2020)
describe

foreach y in wagez {
	capture drop f f2 f3 f4 f5
	gen f = f.`y'
	gen f2 = f2.`y'
	gen f3 = f3.`y'

	egen `y'3 = rowmean(`y' f f2)
}

foreach x in wagez3 { //agi agi3 agi3med wage wage3 wage3med
	*gen ln`x' = ln(`x')
	egen n`x' = count(`x'), by(agecyr cutyr)
	egen r`x' = rank(`x') , by(agecyr cutyr)
	gen p`x' = 100*r`x'/n`x'
	summ p`x', detail
	drop r`x' n`x'


}



gen i_married = (fil_stat==2 |fil_stat==3)
replace i_married = . if inrange(taxyr_out,2019,2020)
gen i_married0 = i_married
replace i_married0 = 0 if i_married==. & !inrange(taxyr_out,2019,2020)
gen i_married3 = max(i_married0, f.i_married0, f2.i_married0)
